package com.osce.web.controller.websocket;

import com.osce.common.utils.spring.SpringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zzx
 * scoket注册类
 */
@Configuration
@EnableWebSocket
public class WebSocketController implements WebSocketConfigurer {

    private static final Map<String, String> BEAN_MAP = new HashMap<String, String>(){{
        put("scoreExPlaceHandler", "score-exam-place");//考站屏幕socket连接
        put("scoreExWaitingHandler", "exam-student-screen");//候考厅socket连接
        put("scoreExamPlaceDoorHandler", "score-exam-place-door");//考站门口展示屏socket连接
    }};

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        BEAN_MAP.forEach((bean, path) -> {
            registry.addHandler(SpringUtils.getBean(bean), path).setAllowedOrigins("*");
        });
    }
}
